package com.kaifamiao.niofile;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;

public class PathTest {

    public static void main(String[] args) {

        // Paths.get 是从 JDK 1.7 开始提供的方法
        // 通过 Paths 类提供的支持获得 Path 实例
        Path path = Paths.get( "D:/kaifamiao", "application", "VSCode" );
        System.out.println( path );

        // Path.of 是从 JDK 11 开始提供的方法
        path = Path.of("C:/Users", "Administrator", "AppData", "Local" );
        System.out.println( path );

        // 获得整个路径中每部分名称的个数
        int count = path.getNameCount();
        System.out.println( count );

        for ( int i = 0; i < count; i++ ) {
            // 获得指定部分的名称
            Path name = path.getName(i);
            System.out.println( name );
        }

        System.out.println( "- - - - - - -" );

        Iterator<Path> itor = path.iterator();
        while( itor.hasNext() ) {
            System.out.println( itor.next() );
        }

        System.out.println( "- - - - - - -" );

        System.out.println( path.toAbsolutePath() );
        System.out.println( path.toFile() ); // java.io.File
        System.out.println( path.toUri() ); // java.net.URI

    }

}
